package com.fruit.dao.impl;

import com.fruit.dao.BaseDAO;
import com.fruit.dao.FruitCategoryDAO;
import com.fruit.pojo.FruitCategory;
import com.sun.org.apache.bcel.internal.generic.RETURN;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class FruitCategoryDAOImpl implements FruitCategoryDAO {

    private BaseDAO baseDAO = new BaseDAO();

    @Override
    public List<FruitCategory> getCategoryList() throws Exception {
        try {
            String sql = "select ID,NAME from FRUIT_CATEGORY";
            ResultSet resultSet = baseDAO.excuteQuery(sql, null);
            List<FruitCategory> list = new ArrayList<>();
            while (resultSet.next()) {
                FruitCategory category = new FruitCategory();
                category.setId(resultSet.getInt("ID"));
                category.setName(resultSet.getString("NAME"));
                list.add(category);
            }
            return list;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            baseDAO.closeAll();
        }
    }
}
